package g

import (
	"encoding/json"
	"net/http"
)

type Response struct {
	Code int         `json:"code"`
	Msg  string      `json:"msg"`
	Resp interface{} `json:resp`
}

func HandleRespErr(
	w http.ResponseWriter,
	statusCode int,
	msg string) {
	res, _ := json.Marshal(&Response{
		Code: statusCode,
		Msg:  msg,
		Resp: nil,
	})
	w.Write(res)
}

func CheckErr(w http.ResponseWriter, err error) bool {
	if err != nil {
		Errorf("Internal server error: %v.", err.Error())
		HandleRespErr(w, 1, "Internal server error!")
		return true
	}

	return false
}
